<template>
    <div class="list-wrap">
        <headerNav title="账单"/>
        <!-- <div class="header">
            <div class="left" @click="show = true">本月</div>
            <div class="right">支出 ¥ 4368</div>
        </div> -->
        <div v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" :infinite-scroll-immediate-check="true" infinite-scroll-distance="30">
            <div class="bill-list" v-if="list.length">
                <div class="bill-li" v-for="(item, index) in list" :key="index">
                    <div class="left">
                        <div class="title">{{item.accountName}} &nbsp;&nbsp;&nbsp; {{item.operName}}</div>
                        <div class="time">{{item.modiTime}}</div>
                    </div>
                    <div class="right">{{item.operAmt}}</div>
                    <div class="line"></div>
                </div>
            </div>
            <div class="tips" v-show="busy">{{tips}}</div>
        </div>
        <van-datetime-picker
            v-show="show"
            v-model="currentDate"
            type="year-month"
            :min-date="minDate"
            :formatter="formatter"
            @confirm="confirm"
            @cancel="cancel"
            @change="change"
            />
    </div>
</template>

<script>
import Vue from 'vue';
import { DatetimePicker, List } from 'vant';
import { accountLog } from "../../../api/page.js";

Vue.use(DatetimePicker).use(List);
export default {
    data() {
        return {
            show: false,
            currentDate: new Date(),
            list: [],
            pageNum: 1,
            pageSize: 10,
            busy: false,
            tips: "页面正在加载中...",
            temp: false
        };
    },
    mounted() {
        this.pageNum = 1
        this.accountLog()
    },
    methods: {
        loadMore() {
            console.log(this.pageNum, this.list.length)
            if (!this.busy && !this.temp) {
                this.accountLog()
            }
        },
        accountLog() {
            const _this = this
            const obj = {
                "pageNum": this.pageNum,
                "pageSize": this.pageSize,
            }
            _this.busy = true
            _this.temp = true
            accountLog(obj).then(res => {
                _this.temp = false
                _this.busy = false;
                _this.list = _this.list.concat(res.data.list)
                _this.pageNum = _this.pageNum + 1
                console.log(_this.pageNum)

                if (res.data.list.length < 10) {
                    _this.busy = true;
                    this.tips = "页面数据全部加载完毕"
                }
            })
             
        },
        formatter(type, value) {
            if (type === 'year') {
                return `${value}年`;
            } else if (type === 'month') {
                return `${value}月`
            }
            console.log(value)
            return value;
        },
        change(e) {
            e.getValues()
            console.log(e.getValues())
        },
        confirm() {
            this.show = false
            console.log(this.currentDate)
        },
        cancel() {
            this.show = false
            console.log(this.currentDate)
        }
    }
};
</script>

<style scoped lang="less">
.list-wrap {
    padding-bottom: 0.8rem;
    position: relative;
}
.bill-list {
    background: #fff;
    padding-top: 1.226667rem;
    .bill-li {
        height: 1.813333rem;
        padding: 0 0.4rem;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items:  center;
        position: relative;
        overflow-x: hidden;
        .line {
            position: absolute;
            width: 100%;
            bottom: 0;
            &::after {
                content: " ";
                position: absolute;
                left: 0;
                bottom: 0;
                width: 100%;
                height: 0.026667rem;
                background: #ccc;
                -webkit-transform: scaleY(.5);
                transform: scaleY(.5);
            }
        }
        .left {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            justify-content: space-evenly;
            .title {
                font-size: 0.4rem;
                color: #333;
                font-weight: bold;
            }
            .time {
                font-size: rgba(51, 51, 51, .8);
                font-size: 0.32rem;
            }
        }
        .right {
            font-size: 0.48rem;
            color: #333;
            font-weight: bold;
        }
    }
}
.tips {
    width: 100%;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.373333rem;
    color: #333;
}
</style>
